package cn.bone.alibabacloud.service.impl;

import cn.bone.alibabacloud.mapper.AccountMapper;
import cn.bone.alibabacloud.service.IAccountService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.concurrent.TimeUnit;

@Service
@Slf4j
public class AccountServiceImpl implements IAccountService {

    @Resource
    private AccountMapper accountMapper;

    public void decrease(Integer userId, Integer money){

        log.info("---> 做账户余额扣除");

        //模拟超时异常，全局事务回滚
        try {
            TimeUnit.SECONDS.sleep(10);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        accountMapper.decrease(userId,money);
        log.info("---> 做账户余额扣除 结束");
    }
}
